import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {NzSafeAny} from 'ng-zorro-antd/core/types';
import {NzMessageService} from 'ng-zorro-antd/message';
import {NzUploadChangeParam, NzUploadFile} from "ng-zorro-antd/upload";
import {exportFileUrl, importFileUrl} from "../../../configs/constant";
import {FileManageService} from "../../../core/services/http/file-manage.service";

@Component({
  selector: 'app-card-table-wrap',
  templateUrl: './card-table-wrap.component.html',
  styleUrls: ['./card-table-wrap.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class CardTableWrapComponent implements OnInit {
  fileList: NzUploadFile[] = [];
  importUrl = importFileUrl;
  exportUrl = exportFileUrl;
  @Input() needDownBtn: boolean;
  @Input() needDelBtn: boolean;
  @Input() needAddBtn: boolean;
  @Input() needExportBtn: boolean;
  // @Input() needAllDelBtn: boolean;
  @Input() needImportBtn: boolean;
  @Output() add = new EventEmitter<NzSafeAny>();
  @Output() del = new EventEmitter<NzSafeAny>();
  @Output() down = new EventEmitter<NzSafeAny>();
  // @Output() delAll = new EventEmitter<NzSafeAny>();
  @Output() export = new EventEmitter<NzSafeAny>();
  @Output() import = new EventEmitter<NzSafeAny>();

  // @Input() actionCode!: ActionCodeObj;

  constructor(private dataService: FileManageService, private message: NzMessageService) {
    this.needAddBtn = false;
    this.needExportBtn = false;
    // this.needAllDelBtn = false;
    this.needDelBtn = false
    this.needImportBtn = false;
    this.needDownBtn = false;
  }


  handleChange(info: NzUploadChangeParam): void {
    if (info.type === 'success' && info.file.response.code === 0) {
      this.message.success(`${info.file.name} successfully`);
      this.fileList = [];
      this.import.emit();
    } else {
      this.message.error(`${info.file.response.msg}`);
      this.fileList = [];
    }
  }

  addBtnClick(): void {
    this.add.emit();
  }

  downBtnClick(): void {
    this.down.emit();
  }

  /*delAllBtnClick(): void {
    this.delAll.emit();
  }
*/

  exportBtnClick(): void {
    this.export.emit();
  }

  delBtnClick(): void {
    this.del.emit();
  }

  ngOnInit(): void {
  }

}
